package com.finer.service.impl;

import com.finer.entity.finance.FinerPayRequest;
import com.finer.dao.FinerPayRequestDao;
import com.finer.service.FinerPayRequestService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 付款需求表(FinerPayRequest)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:38
 */
@Service("finerPayRequestService")
public class FinerPayRequestServiceImpl implements FinerPayRequestService {
    @Resource
    private FinerPayRequestDao finerPayRequestDao;

    /**
     * 通过ID查询单条数据
     *
     * @param Id 主键
     * @return 实例对象
     */
    @Override
    public FinerPayRequest queryById(Integer Id) {
        return this.finerPayRequestDao.queryById(Id);
    }

    /**
     * 分页查询
     *
     * @param finerPayRequest 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerPayRequest> queryByPage(FinerPayRequest finerPayRequest, PageRequest pageRequest) {
        long total = this.finerPayRequestDao.count(finerPayRequest);
        return new PageImpl<>(this.finerPayRequestDao.queryAllByLimit(finerPayRequest, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerPayRequest 实例对象
     * @return 实例对象
     */
    @Override
    public FinerPayRequest insert(FinerPayRequest finerPayRequest) {
        this.finerPayRequestDao.insert(finerPayRequest);
        return finerPayRequest;
    }

    /**
     * 修改数据
     *
     * @param finerPayRequest 实例对象
     * @return 实例对象
     */
    @Override
    public FinerPayRequest update(FinerPayRequest finerPayRequest) {
        this.finerPayRequestDao.update(finerPayRequest);
        return this.queryById(finerPayRequest.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param Id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer Id) {
        return this.finerPayRequestDao.deleteById(Id) > 0;
    }
}
